package com.leadnews.mapper;

import com.leadnews.pojo.Wemedia;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.leadnews.vo.front.WemediaFront;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 自己
 * @description 针对表【wemedia】的数据库操作Mapper
 * @createDate 2023-01-09 21:43:01
 * @Entity com.leadnews.pojo.WemediaFront
 */
public interface WemediaMapper extends BaseMapper<Wemedia> {
//    @Select("SELECT  a.* from (SELECT  * from wemedia where user_id=#{id} UNION all select * from wemedia where status=1) a group by a.id order by  a.status asc,a.istop desc,a.create_time desc")
    @Select("SELECT * from wemedia where id not in (select id from wemedia where user_id!=#{id} and status=0) order by  status asc,istop desc,create_time desc")
    List<Wemedia> findAllWemedia(@Param("id") Object id);
    @Select("<script>" +
            "select w.*,u.username from wemedia w,user u " +
            "where " +
            "w.user_id=u.id  " +
            "<when test='userId!=null'>" +
            "  and w.user_id like" +
            " '%${userId}%'" +
            "</when>"+
            "<when test='status!=null'>"+
            " and w.status =#{status} " +
            "</when>"+
            "<when test='istop!=null'>"+
            "and w.istop =#{istop} " +
            "</when>"+
            "and w.create_time " +
            "between #{createTime} and #{endTime}" +
            " order by w.create_time desc limit #{i},#{i1}" +
            "</script>")
    List<WemediaFront> findWemediaFront(@Param("i") int i,@Param("i1") int i1, @Param("userId") String userId,@Param("status") String status, @Param("istop")String istop, @Param("createTime") String createTime, @Param("endTime") String endTime);


}